<?php
$resultsXpag=10;
$pag_selected=isset($_REQUEST['sel_num_pag'])?$_REQUEST['sel_num_pag']:1;
$pag_1 =isset($_REQUEST['prim_pag'])?$_REQUEST['prim_pag']:1;

function getHiddensInForm(){
    global $pag_1;
    $html_hdd = '';
    $html_hdd.='<input type="hidden" name="prim_pag" id="prim_pag" value="'.$pag_1.'"/>';
    $html_hdd.='<input type="hidden" name="sel_num_pag" id="sel_num_pag" value="'.$pag_1.'"/>';
    return $html_hdd;
}
//-----------------------------------------------------------
function getPaginador($total_regs, $urlbase, $form_id){
    $html_pag='';
    global $resultsXpag, $pag_selected, $pag_1;
    $cant_pags = ceil($total_regs/$resultsXpag);
    $html_pag .= '<script type="text/javascript">var form_id="'.$form_id.'"</script>';
    $html_pag .= '<script type="text/javascript" src="'.$urlbase.'paginador.js"></script>';
    //$html_pag .= getHiddensInForm();
    $html_pag.='<table><tr>';
    if($pag_1 > 2){
        if($pag_selected == 1){
            $html_pag.='<td><div class="numpagsel" onclick="selectFirst(this);"><input type="hidden" name="" value="1"/>1</div></td>';
        }else{
            $html_pag.='<td><div class="numpag" onclick="selectFirst(this);"><input type="hidden" name="" value="1"/>1</div></td>';
        }
        $html_pag.='<td><div class="numpag" onclick="prev('.$pag_1.');"> ...</div></td>';
    }
    for($i=$pag_1; $i<=$cant_pags; $i++){
        if($i == $pag_selected){
            $html_pag.='<td><div class="numpagsel" onclick="selectThis(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
        }else{
            $html_pag.='<td><div class="numpag" onclick="selectThis(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
        }
        if(($i > $pag_1+4) && ($pag_selected < $cant_pags) && ($pag_1+5 < $cant_pags)){
            $html_pag.='<td><div class="numpag" onclick="next('.$i.');"> ...</div></td>';
            $i=$cant_pags;
            if($pag_selected == $i){
                $html_pag.='<td><div class="numpagsel" onclick="selectLast(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
            }else{
                $html_pag.='<td><div class="numpag" onclick="selectLast(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
            }
        }
    }
    $html_pag.='</tr></table>';
    return $html_pag;
}

class paginator {

    public $resultsXpag;
    public $pag_selected;
    public $pag_1;

    function __construct($resultsXpag, $pag_selected, $pag_1) {
        $this->resultsXpag = $resultsXpag;
        $this->pag_selected = $pag_selected;
        $this->pag_1 = $pag_1;
    }

    function getHiddensInForm(){
        $html_hdd = '';
        $html_hdd.='<input type="hidden" name="prim_pag" id="prim_pag" value="'.$this->pag_1.'"/>';
        $html_hdd.='<input type="hidden" name="sel_num_pag" id="sel_num_pag" value="'.$this->pag_1.'"/>';
        return $html_hdd;
    }
    function showReg($num_r){
        return ($num_r > (($this->pag_selected-1) * $this->resultsXpag) && $num_r <= ($this->pag_selected * $this->resultsXpag));
    }
    function getPaginator($total_regs, $urlbase, $form_id){
        $html_pag='';
        $cant_pags = ceil($total_regs/$this->resultsXpag);
        $html_pag .= '<script type="text/javascript">var form_id="'.$form_id.'"</script>';
        $html_pag .= '<script type="text/javascript" src="'.$urlbase.'paginador.js"></script>';
        //$html_pag .= getHiddensInForm();
        $html_pag.='<table><tr>';
        if($this->pag_1 > 2){
            if($this->pag_selected == 1){
                $html_pag.='<td><div class="numpagsel" onclick="selectFirst(this);"><input type="hidden" name="" value="1"/>1</div></td>';
            }else{
                $html_pag.='<td><div class="numpag" onclick="selectFirst(this);"><input type="hidden" name="" value="1"/>1</div></td>';
            }
            $html_pag.='<td><div class="numpag" onclick="prev('.$this->pag_1.');"> ...</div></td>';
        }
        for($i=$this->pag_1; $i<=$cant_pags; $i++){
            if($i == $this->pag_selected){
                $html_pag.='<td><div class="numpagsel" onclick="selectThis(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
            }else{
                $html_pag.='<td><div class="numpag" onclick="selectThis(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
            }
            if(($i > $this->pag_1+4) && ($this->pag_selected < $cant_pags) && ($this->pag_1+5 < $cant_pags)){
                $html_pag.='<td><div class="numpag" onclick="next('.$i.');"> ...</div></td>';
                $i=$cant_pags;
                if($this->pag_selected == $i){
                    $html_pag.='<td><div class="numpagsel" onclick="selectLast(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
                }else{
                    $html_pag.='<td><div class="numpag" onclick="selectLast(this);"><input type="hidden" name="" value="'.$i.'"/>'.$i.'</div></td>';
                }
            }
        }
        $html_pag.='</tr></table>';
        return $html_pag;
    }
}
?>

        